#ifndef DEMO_HPP
#define DEMO_HPP
#include "Define.h"

struct Demo
{
    std::string name;
    int b;
    SERIALIZE(Demo,Demo,name,b)
};

struct stObject{
    int id;
    int time;
    string text;
    //第1个参数父类类名（没有父类填自己的类名）,第2个参数自己的类名, 之后的是参数列表
    SERIALIZE(stObject,stObject,id,time,text)
};
struct A
{
    std::string name;
    char s[20];
    char s2[3];
    char s3[4];
    float f[5];
    SERIALIZE(A,A,name,s,s2,s3,f)
};

struct B
{
    vector<int> v;
    vector<string> v2;
    SERIALIZE(B,B,v,v2)
};

struct C : stObject
{

    Demo a1;
    SERIALIZE(stObject,C,a1)
};


void test()
{
    {
        stObject obj1;
        obj1.id = 20;
        obj1.time = 3600;
        obj1.text = "stObject";
        cout<<"obj1:"<<obj1.id<<" "<<obj1.time<<" "<<obj1.text<<endl;
        string s1 = obj1.Serialize();
        stObject obj2;
        obj2.UnSerialize(s1);
        cout<<"obj2:"<<obj2.id<<" "<<obj2.time<<" "<<obj2.text<<endl;
    }

    {
        A a1;
        a1.name = "A";
        memset(a1.s,0x00,20);
        strcpy(a1.s,"apple");
        memset(a1.s2,0x00,3);
        strcpy(a1.s2,"bb");
        memset(a1.s3,0x00,4);
        strcpy(a1.s3,"ccc");
        for(int i = 0;i < 5;i++)
        a1.f[i] = i;
        cout<<"a1:"<<a1.s<<" "<<a1.s2<<" "<<a1.s3;
        for(int i = 0; i < 5; i++)
        cout<<" "<<a1.f[i];
        cout<<endl;
        string s2 = a1.Serialize();
        A a2;
        a2.UnSerialize(s2);
        cout<<"a2:"<<a2.s<<" "<<a2.s2<<" "<<a2.s3;
        for(int i = 0; i < 5; i++)
            cout<<" "<<a2.f[i];
        cout<<endl;
    }

    {
        B b1;
        b1.v.push_back(23);
        b1.v.push_back(26);
        b1.v.push_back(36);
        b1.v2.push_back("aaaaaaaaaaaaaaa");
        b1.v2.push_back("bbbbbbbbbbbbbbb");
        b1.v2.push_back("ccccccccccccccc");
        cout<<"b1:"<<b1.v[0]<<" "<<b1.v[1]<<" "<<b1.v[2]<<" ";
        cout<<b1.v2[0]<<" "<<b1.v2[1]<<" "<<b1.v2[2]<<endl;
        string s3 = b1.Serialize();
        B b2;
        b2.UnSerialize(s3);
        cout<<"b2:"<<b2.v[0]<<" "<<b2.v[1]<<" "<<b2.v[2]<<" ";
        cout<<b2.v2[0]<<" "<<b2.v2[1]<<" "<<b2.v2[2]<<endl;
    }

    {
        C c1;
        c1.a1.b = 33;
        c1.a1.name = "Demo";
        c1.id = 433;
        c1.text = "C";
        c1.time = 60;
        cout<<"c1:"<<c1.a1.b<<" "<<c1.a1.name<<" "<<c1.id<<" "<<c1.text<<" "<<c1.time<<endl;
        string s4 = c1.Serialize();
        C c2;
        c2.UnSerialize(s4);
        cout<<"c2:"<<c2.a1.b<<" "<<c2.a1.name<<" "<<c2.id<<" "<<c2.text<<" "<<c2.time<<endl;
    }
}

#endif // DEMO_HPP
